﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace BingMapsSample
{
    public class KQueryable<T> : IQueryable<T>
    {
        public Expression Expression { get; private set; }
        public IQueryProvider Provider { get; private set; }

        public Type ElementType
        {
            get { return typeof(T); }
        }

        [DebuggerHidden]
        public KQueryable(IQueryProvider provider, Expression expression = null)
        {
            if (provider == null) throw new ArgumentNullException("provider");

            Expression = expression ?? Expression.Constant(this);
            Provider = provider;
        }

        [DebuggerHidden]
        public IEnumerator<T> GetEnumerator()
        {
            return Provider.Execute<IEnumerable<T>>(Expression).GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotSupportedException();
        }
    }
}
